package com.evildog.workspace.life.application.controller;

import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.object.PageQuery;
import java.util.List;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.life.application.model.AlbumPageParam;
import com.evildog.workspace.life.application.model.AlbumParam;
import com.evildog.workspace.life.application.vo.AlbumPageVO;
import com.evildog.workspace.life.application.vo.AlbumVO;
import com.evildog.workspace.life.application.bo.AlbumBO;
import com.evildog.workspace.life.application.bo.AlbumPageBO;
import com.evildog.workspace.life.application.convert.AlbumConvert;
import com.evildog.workspace.life.application.service.AlbumService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 * album Controller
    相册
 * </p>
 *
 * @author evildog
 * @since 2020-07-18
 */
@RestController
@RequestMapping("/albums")
@AllArgsConstructor
@Api(tags = "album相关接口")
public class AlbumController {
    private AlbumService albumService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody AlbumParam albumParam) {
        return ResultGenerator.status(albumService.save(AlbumConvert.INSTANCE.convert(albumParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(albumService.remove(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> delete(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(albumService.removeByIds(ids));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody AlbumParam albumParam) {
        return ResultGenerator.status(albumService.updateById(id, AlbumConvert.INSTANCE.convert(albumParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<AlbumVO> getById(@PathVariable("id") Long id) {
        AlbumBO albumBO = albumService.getDetailById(id);
        return ResultGenerator.success(AlbumConvert.INSTANCE.convert(albumBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<AlbumPageVO>> getPageList(AlbumPageParam albumPageParam,PageQuery query){
        PagedResult<AlbumPageBO> albumPageBO = albumService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(albumPageParam),
                        AlbumConvert.INSTANCE.convert(albumPageParam));
        return ResultGenerator.success(AlbumConvert.INSTANCE.convert(albumPageBO));
    }

}
